<link rel="stylesheet" href="${request.contextPath}/css/suredy-tree.css">
<div class="container-fluid suredy-form" style="padding-top: 0">
	<div class="row">	
	<form name="form" id="form">
	<#if user??>	
		<input type="hidden" readonly="readonly" id="unitId" name="unitId" value="${user.unitId}" />
		<input type="hidden" readonly="readonly" id="id" name="id" value="${user.id}" />
		<div class="form-group">
			<div class="input-group">
				<div class="input-group-addon">单位/部门</div>
				<input type="text" class="form-control" readonly="readonly" id="parentName" value="${user.unitName}" />
				<div class="input-group-addon btn btn-default btn-load-ou-tree" data-toggle="collapse" href="#ou-tree" aria-expanded="false" aria-controls="ou-tree">
					<i class="icon-sitemap"></i>
				</div>
			</div>
		</div>
		<div class="collapse" id="ou-tree" style="border-top:1px solid #ddd; max-height:300px; overflow:auto;">
			<div class="suredy-tree normal ou-tree-for-parent">加载中……</div>
		</div>
		<div class="row">&nbsp;</div>	
	
		<div class="form-group">
			<div class="input-group">
				<div class="input-group-addon">真实姓名</div>
				<input type="text" class="form-control" id="name" name="name" value="${user.name}" />
			</div>
		</div>	
		
		<div class="form-group">
			<div class="input-group">
				<div class="input-group-addon">用户简称</div>
				<input type="text" class="form-control" id="alias" name="alias" value="${user.alias}" />
			</div>
		</div>
		
		<div class="form-group">
			<div class="input-group">
				<div class="input-group-addon">职衔职务</div>
				<input type="text" class="form-control" id="title" name="title" value="${user.title}" />
			</div>
		</div>	
		
		<div class="form-group">
			<div class="input-group">
				<div class="input-group-addon">邮件地址</div>
				<input type="text" class="form-control" id="email" name="email" value="${user.email}" />
			</div>
		</div>								
		
		<div class="form-group">
			<div class="input-group">
				<div class="input-group-addon">显示顺序</div>
				<input type="text" class="form-control" id="sort" name="sort" value="${user.sort}" />
			</div>
		</div>	
		
		<div class="form-group">
			<div class="input-group">
				<div class="input-group-addon">用户描述</div>
				<textarea class="form-control" rows="3" id="description" name="description">${user.description}</textarea>
			</div>
		</div>	
		</#if>		
							
		<div class="text-center">
			<div class="btn btn-info" id="btn-save" >
				<i class="icon-save"></i> 保存
			</div>
		</div>	
	</form>	
	</div>
</div>
<script src="${request.contextPath}/js/suredy-tree.js"></script>
<script type="text/javascript">
	$(document).ready(function() {
		var OUTree = function() {
			$('.ou-tree-for-parent').tree('ou/tree', {
				click : function() {
					var nodeText = $(this).text();
					if (nodeText.indexOf('[单位]') == -1 ) {
						var nodeData = $.suredy.tree.data($(this));
						$('#parentName').val(nodeText);
						$('#unitId').val(nodeData.id);
					}  else {
						$('#unitId').val('');
					}
				}
			});
		};

		OUTree();	
			
		$('#btn-save').click(function() {
			var unitId = $('#unitId').val();
			var name = $('#name').val();

			if (unitId == '') {
				alert('请选择单位/部门！');
				return;
			}

			if (name == '') {
				alert('请填写用户姓名！');
				return;
			}

			$.ajax({
				url : 'user/edit-save.do',
				dataType : 'json',
				type : 'POST',
				data : $('#form').serialize(),
				success : function(success) {
					if (!success) {
						alert('修改用户失败！');
					} else if (!success.success) {
						alert('修改用户失败！\n\n' + success.msg);
					} else {
						alert('修改用户成功！');
						$.suredy.loadContent('user/list.do');
						$.suredy.closeModal();
					}
				},
				error : function(a, b, c) {
					alert('服务器错误! ' + b);
				}
			});
		});	
	});
</script>	
